package com.lanou.musicbox.adapter.onlinemusic;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.Recommendsongs;
import com.lanou.musicbox.utils.VolleySingleton;

import java.util.ArrayList;

/**
 * Created by dllo on 15/10/30.
 */
public class RecommendListViewAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<Recommendsongs.ContentEntity.SongListEntity>data;
    private ImageLoader imageLoader;
    private Recommendsongs.ContentEntity.SongListEntity entity;

    public  RecommendListViewAdapter(Context context,ArrayList<Recommendsongs.ContentEntity.SongListEntity>data){
        this.context=context;
        this.data=data;
        imageLoader= VolleySingleton.getInstance(context).getImageLoader();

    }
    @Override
    public int getCount() {
        return data!=null&&data.size()>0?data.size():0;
    }

    @Override
    public Object getItem(int position) {
        return data!=null&&data.size()>0?data.get(position):0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.recommend_songs_item,null);
            viewHolder=new ViewHolder();
            viewHolder.songs_imager= (ImageView) convertView.findViewById(R.id.songs_imager);
            viewHolder.recommend_name= (TextView) convertView.findViewById(R.id.recommend_name);
            viewHolder.recommend_singer= (TextView) convertView.findViewById(R.id.recommend_singer);
            viewHolder.recommend_content= (TextView) convertView.findViewById(R.id.recommend_content);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        entity = (Recommendsongs.ContentEntity.SongListEntity) getItem(position);
        viewHolder.recommend_name.setText(entity.getTitle());
        viewHolder.recommend_singer.setText(entity.getAuthor());
        viewHolder.recommend_content.setText(entity.getRecommend_reason());
        ImageLoader.ImageListener imageListener= ImageLoader.getImageListener(viewHolder.songs_imager,R.mipmap.loading,R.mipmap.loading);
        imageLoader.get(entity.getPic_small(),imageListener);
        return convertView;
    }
    class ViewHolder{
        private ImageView songs_imager;
        private TextView recommend_name;
        private TextView   recommend_singer;
        private TextView recommend_content;


    }
}
